package controllers

import (
	"github.com/emicklei/go-restful/v3"
	"github.com/rs/zerolog/log"
	"webGoDemo/common"
	"webGoDemo/model"
	"webGoDemo/services/user"
)

/**
controller 层
*/
// WebService creates a new service that can handle REST requests for User resources.

func FindAllUsers(request *restful.Request, response *restful.Response) {

	request.SetAttribute("resource", "User")
	// 获取对应的service
	userService := new(user.ServiceImp)

	result, err := userService.FindAll()

	log.Info().Interface("result:", result).Send()

	err = request.ReadEntity(&model.User{})
	if err != nil {
		return
	}

	if err != nil {
		common.Out(response, common.Fail("10230120", err.Error()))
	} else {
		common.Out(response, common.OK(result))
	}

}
